package erwiki.ui.app.parts.attachments;

import org.apache.commons.io.FileUtils;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.elwiki_data.AttachmentContent;

public class AttachmentsLabelProvider extends LabelProvider implements ITableLabelProvider {

	private static final long serialVersionUID = 1L;

	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getColumnText(Object element, int columnIndex) {
		String result = "";
		if (element instanceof AttachmentContent atc) {
			result = switch (columnIndex) {
			case 0 -> atc.getPageAttachment().getName();
			case 1 -> Integer.toString(atc.getVersion());
			case 2 -> atc.getCreationDate().toString(); // :FVK: workaround.
			case 3 -> FileUtils.byteCountToDisplaySize(atc.getSize());
			case 4 -> "type";
			case 5 -> atc.getAuthor();
			case 6 -> atc.getChangeNote();
			default -> "";
			};
		}

		return result;
	}

}
